<template>
  <div class="login">
    <!-- 登录 -->

    <van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="username"
      name="loginname"
      label="用户名"
      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="password" 
      type="password"
      name="password"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      登录
    </van-button>
  </div>
</van-form>

<!-- 注册 -->
<van-button type="primary" to="/regisiter" size="small">注册</van-button>

  </div>
</template>    

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router' 
import useUserStore from '@/store/modules/user'


//用户相关的store
const store = useUserStore()  

//路由对象
const router = useRouter()

//用户名与密码
const username = ref('13199876612') 
const password = ref('123456')

// 登录表单提交 
const onSubmit = async(values :LoginUser) => { 
      console.log('submit', values);
     const  loginResult = await store.loginAction(values)
    //  console.log("登陆结果",loginResult)
    if(loginResult){
      router.push("/mine")
    }
     };
 



</script> 

<style lang="less" scoped>

</style>
